require 'rubygems'
require 'hpricot'
require 'net/http'
require 'open-uri'
IRCBot::Plugin.define "urbandict" do
	help_string "Looks up stuff on the urban dictionary."
	def command(user,target,message,usermask)
		Thread.new {page = Hpricot(open("http://www.urbandictionary.com/define.php?term=#{message.gsub(" ","+")}"))
		if page.at("div.definition")
			definition = page.at("div.definition").inner_html.to_s.gsub("<br />","").gsub("<b>",2.chr).gsub("</b>",2.chr).gsub(/<a(.+?)>/,0x1F.chr).gsub("</a>",0x1F.chr).gsub(/<(.+?)>/,"").gsub("\n"," ").gsub("\r"," ").strip.gsub("&quot;","\"")
			privmsg(target,definition)
		else
			privmsg(target,"Not found.")
		end
		}
	end
end
